<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="/misc/css/base.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/btnicon.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/reset_admin.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/adminmenu.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/newadmin.css"  />
<script type="text/javascript" src="/misc/vendors/jquery/jquery_1.2.6.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js_build.js"></script>
<script type="text/javascript" >
var baseUrl = "<?=$themeUrl?>";
var grids;
var rs_sendpi = {json_encode($rs_sendpi)};
var rs_send_vege = {json_encode($rs_send_vege)};
$().ready(function(){
	if(rs_sendpi.status == '1'){
		$('#opt_div').remove();
		$('#error_div').show();
		$('#error_div_str').html('配送正在包装生产中，如需修改配送菜品，请拨打客服电话 400-0900-917 ');
		
		$('.vegetext').attr('readonly','readonly');
		$('.numclick').hide();
		return false;
	}
	var noslt = true;
	for(var i=0; i<rs_send_vege.length; i++){
		if(rs_send_vege[i]['fixed'] ==  '0'){
			noslt = false;
		}
	}
	if(noslt){
		$('#opt_div').remove();
		$('#error_div').show();
		$('#error_div_str').html('配送中暂无 自选菜品 ，如有疑问，请拨打我们的客服电话 400-0900-917');
		
		$('.vegetext').attr('readonly','readonly');
		$('.numclick').hide();
		return false;
	}	
	$('#opt_div').show();
	$('#error_div').remove();
});
</script>
</head>
<style type="text/css">

.statusout{
position:relative;
}
.statusdiv{
float:left;
margin:5px;
border:1px solid #EBEBEB;
padding:5px;
color:#CCCCCC;
}
.statusdiv_on{
color:#FF6633;
background:url(/misc/images/yes.gif) top 5px left 3px no-repeat #FFFFCC;
padding-left:23px;
}
.vegediv_fix{
border: 1px solid #B2D9F0;
color: #0082CB;
background-color:#E8F3FF;
float: left;
margin: 1px 3px;
padding: 3px;
text-decoration: none;
}

.vegediv_slt{
border: 1px solid #CCCCCC;
color: #999999;
float: left;
margin: 1px 3px;
padding: 3px;
text-decoration: none;
}
.vegediv_slt_on{
padding-left:20px;
background:url(/misc/images/yes.gif) top 5px left 3px no-repeat #E8F3FF;

border: 1px solid #B2D9F0;
color: #0082CB;
}


.vegediv_slt{
cursor:pointer;
}



.sltvege_div{
float:left;
padding:5px;
margin:5px;
}



/* 配送蔬菜选择表格样式 */
table.vegetable{
border-collapse:collapse;
width:325px;
}
table.vegetable th{
background-color:#FFFFCC;
color:#666666;
padding:5px;
border:1px solid #CCCCCC;
}
table.vegetable td{
background-color:#fcfcfc;
color:#333333;
padding:5px;
border:1px solid #CCCCCC;
} 
input.vegetext{
width:50px;
text-align:center;
}


.numclick{
background-color:#C3CDDC;
color:#606E7B;
border:1px solid #929CA7;
cursor:pointer;
} 
</style>
<body   style="background-color:#fcfcfc"> 
<script type="text/javascript">
var url_save = '/user/now_modify'; 

var rs_send = {json_encode($rs_send)};
var rs_sendpi = {json_encode($rs_sendpi)};
var rs_sendfen = {json_encode($rs_sendfen)};
var rs_send_vege = {json_encode($rs_send_vege)};
var rs_veges = {json_encode($rs_veges)};
var nownum = 0;
$().ready(function(){  
	showLoading();  
	
	setInterval(function(){
		var nowsltnum = 0;
		$('#slt_tbody .sltvege_tr').each(function(){
			var myid = $(this).attr('myid');
			var vege_num =  parseInt(strToNum($('#slt_vegenum_'+myid).val()),10);
			if(vege_num <= 0){
				vege_num = 0;
			}
			nowsltnum += vege_num;
		});	
		nownum = rs_sendfen.sltnum - nowsltnum;
		if(nownum<0){
			$('#nownum').html('已超出自选总份数，请调整您的选菜！');
		}else{
			$('#nownum').html(''+nownum+'');
		}
	},500);
	
});
/* 保存 */
function fnSave(){
	var nowsltnum = 0;
	var rsslt = [];
	$('#slt_tbody .sltvege_tr').each(function(){
		var myid = $(this).attr('myid');
		var vege_num =  parseInt(strToNum($('#slt_vegenum_'+myid).val()),10);
		if(vege_num <= 0){
			vege_num = 0;
		}
		nowsltnum += vege_num;
		$('#slt_vegenum_'+myid).val(vege_num);
		rsslt.push({
			vege_id:myid,
			vege_num:vege_num,
			"fixed":"0"
		});
	});	
/* 	

		//判断是否超过最大可选项
		for(var ii=0; ii<rsslt.length; ii++){
			var obj = rsslt[ii];
			if(rs_veges[obj.vege_id].maxnum != '' && rs_veges[obj.vege_id].maxnum>0 && obj.vege_num > rs_veges[obj.vege_id].maxnum){
				alert('菜品【'+rs_veges[obj.vege_id].name+'】的最大可选份数为'+rs_veges[obj.vege_id].maxnum+'，请填写小于等于'+rs_veges[obj.vege_id].maxnum+'的默认份数');
				return false;
			}	
		}
 */
	if(rsslt.length>0){
		//判断是否超过最大可选项
		for(var ii=0; ii<rsslt.length; ii++){
			var obj = rsslt[ii];
			if(rs_veges[obj.vege_id].maxnum != '' && rs_veges[obj.vege_id].maxnum>0 && obj.vege_num > rs_veges[obj.vege_id].maxnum){
				alert('菜品【'+rs_veges[obj.vege_id].name+'】的最大可选份数为'+rs_veges[obj.vege_id].maxnum+'，请填写小于等于'+rs_veges[obj.vege_id].maxnum+'的份数');
				return false;
			}	
		}
	}
	
	if(nowsltnum > rs_sendfen.sltnum){
		alert('已超出自选总份数，请调整您的选菜！');
		return false;
	}
	if(nowsltnum < rs_sendfen.sltnum){
		alert('需要填写总共 '+rs_sendfen.sltnum+' 份菜品');
		return false;
	}

  $('button').attr('disabled','disabled');
	$.ajax({
		async:true,
		type:'post',
		url:url_save,
		data:{
			send_id:rs_send.id,
			vegeids:JSON.encode(rsslt)
		},
		success:function(e){
  		$('button').attr('disabled','');
			var ok = errorHandler(e);
			if(ok){　 
				<?PHP
				if(isset($_GET['endfunc'])){
					echo 'parent.'.$_GET['endfunc'].'(ok);';
				}
				?>
				fnReturn();
			}
		}
	});
}
/* 返回 */
function fnReturn(){
	if(defined(parent) && defined(parent.ymPrompt)){
		parent.ymPrompt.close();
	}else{
		window.close();
	}
}


function fnShao(id){
	var vege_num =  parseInt(strToNum($('#slt_vegenum_'+id).val()),10);
	vege_num = vege_num - 1;
	if(vege_num <= 0){
		vege_num = 0;
	}
	$('#slt_vegenum_'+id).val(vege_num);
	
	
	
}
function fnAdd(id){
	var vege_num =  parseInt(strToNum($('#slt_vegenum_'+id).val()),10);
	vege_num = vege_num + 1;
	if(vege_num <= 0){
		vege_num = 0;
	}
	$('#slt_vegenum_'+id).val(vege_num);
	
	
	
}
</script>
 
  
<div style="margin:10px;">
	<div class="blockdiv">
		<div class="titlediv">配送菜品信息</div>
		<table class="mytable" > 
		
			<tr>
				<td class="mylabel"> 配送日期：</td>
				<td class="myinfo" >
					 {$rs_sendpi.senddate} 
				</td> 
			</tr>
			<tr>
				<td class="mylabel"> 主选菜品：</td>
				<td class="myinfo" >
				<?PHP
				foreach($rs_send_vege as $v){
					if($v['fixed'] == '1'){
						echo '<div class="vegediv_fix">'.$v['name'].'('.$v['code'].') '.$v['vege_num'].' 份 </div>';
					}
				}
				?> 
				</td> 
			</tr>
			<tr>
				<td class="mylabel"> 自选菜品总份数：</td>
				<td class="myinfo"   >
					<span style="color:#FF6600;font-size:14px;font-weight:bold">{$rs_sendfen.sltnum}</span> 
				</td>
			</tr>	
			<tr>
				<td class="mylabel"> 自选菜品：</td>
				<td class="myinfo"   >
 
						<table class="vegetable">
							<thead>
								<tr>
									<th>菜品</th>
									<th  >份数</th>
								</tr>
							</thead>	
							<tbody id="slt_tbody">
		
								<?PHP
								foreach($rs_send_vege as $v){
									if($v['fixed'] == '0'){
										 echo '
								<tr myid="'.$v['vege_id'].'" class="sltvege_tr">
									<td>'.$v['name'].'</td>
									<td>
										<button class="numclick" onclick="fnShao('.$v['vege_id'].')">-</button>
										<input type="text"  value="'.$v['vege_num'].'" id="slt_vegenum_'.$v['vege_id'].'" class="vegetext slt_vegenum">
										<button class="numclick" onclick="fnAdd('.$v['vege_id'].')" >+</button>
									</td>
								</tr>											 
										 ';
									}
								}
								?>
							</tbody>
						</table>
				 				

				</td> 
			</tr>
			<tr>
				<td class="mylabel"> 剩余选择份数：</td>
				<td class="myinfo"   >
					<span style="color:#FF6600;font-size:14px;font-weight:bold" id="nownum"> </span>
				</td>
			</tr>	
		</table>		
	</div>
</div>		
 
<div  class="button_div" id="opt_div" style="display:none">
		<button class=" " onclick="fnSave()">保 存</button>
		<span class="gray">或</span> 
		<a href="#" onclick="fnReturn()">取 消</a>
</div> 

<div  class="box" id="error_div" style="margin:20px ;border:1px solid #CCCCCC;color:#FF3333;background:#FEF0E9 url(/misc/images/alert64_64.gif) 5px 5px no-repeat;line-height:80px;padding-left:80px; display:none">
	<div id="error_div_str" style="font-size:16px;" >
		 
	</div>
</div>	


</body>
</html>